package demo02;

import java.io.IOException;
import java.nio.charset.Charset;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.boot.Banner.Mode;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.StringHttpMessageConverter;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication(exclude = { RedisAutoConfiguration.class })
@Configuration
@RequestMapping("/index")
public class HelloApplication {

    @RequestMapping("hello")
    @ResponseBody
    public String hello() {
        return "hello world！ 传智播客111！";
    }
    
    @RequestMapping(value="/helloworld/{username}",method=RequestMethod.POST)
    public String hello1(@PathVariable String username,@RequestParam String pwd) {
    	return "hello world2！"+username+pwd;
    }
    @RequestMapping(value="/helloworld2/{username}",method=RequestMethod.POST)
    public String hello2(@PathVariable String username,@RequestParam String pwd,HttpServletRequest request,
            HttpServletResponse response) {
    	//return "redirect:/index/hello";
    	try {
			response.sendRedirect("/index/hello");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return "redirect:/index/hello";//有restControl的情况下不能用，要用需要改成control
    }
    

    @Bean
    public StringHttpMessageConverter stringHttpMessageConverter() {
        StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("ISO-8859-1"));
        return converter;
    }

    public static void main(String[] args) {
        // SpringApplication.run(HelloApplication.class, args);
        SpringApplication application = new SpringApplication(HelloApplication.class);
        application.setBannerMode(Mode.OFF);
        application.run(args);
    }

}
